<?php

use yii\helpers\Html;
use mdm\admin\components\Helper;
use common\components\TGridView;
use yii\helpers\Url;
use yii\bootstrap\ActiveForm;
use common\helpers\TStringHelper;

/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('common', 'user-credit-log');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="user-credit-log-index">
    <?php echo $this->render('_search', ['params' => $params]); ?>
    <?php
    $gridColumns = [
        [
            'name' => 'selectedIds',
            'class' => 'kartik\grid\CheckboxColumn',
            'checkboxOptions' => function($model, $key, $index, $column) {
                return [
                    'value' => $model->id,
                ];
            }
        ],
        [
            'class' => 'kartik\grid\SerialColumn',
            'header' => Yii::t('common','serial_number'),
        ],
        [
            'attribute' => 'user_id',
            'header' => Yii::t('common', 'user_id'),
        ],
        [
            //'attribute' => 'type',
            'header' => Yii::t('common', 'type'),
            'value' => function($model){
                return TStringHelper::getUserCreditType($model->type);
            }
        ],
        [
            'attribute' => 'oper_type',
            'header' => Yii::t('common', 'oper_type'),
            'value' => function($model) {
                return TStringHelper::getUserCreditOperType($model->oper_type);
            }
        ],
        [
            'attribute' => 'amount',
            'header' => Yii::t('common', 'amount'),
        ],
        [
            'attribute' => 'before',
            'header' => Yii::t('common', 'amount-before'),
        ],
        [
            'attribute' => 'after',
            'header' => Yii::t('common', 'amount-after'),
        ],
        [
            //'attribute' => 'status',
            'header' => Yii::t('common', 'status'),
            'value' => function($model){
                return TStringHelper::getStatusText($model->status);
            }
        ],
        [
            'attribute' => 'created_by',
            'header' => Yii::t('common', 'created_by'),
        ],
        [
            'attribute' => 'created_at',
            'header' => Yii::t('common', 'created_at'),
        ],
        // 'created_from',
        // 'created_ip',
        // 'updated_by',
        // 'updated_at',
        // 'updated_from',
        // 'updated_ip',
        // 'is_deleted',
    ];

    $contentName = Yii::t('common', 'user-credit-log');

    $form = ActiveForm::begin([
        'id' => 'list-form'
    ]);

    echo TGridView::widget([
        'id'=>'grid',
        'dataProvider' => $dataProvider,
        //'filterModel' => $searchModel,
        'columns' => $gridColumns,
        'panel' => [
            'type' => TGridView::TYPE_DEFAULT,
            'heading' => '<h3 class="panel-title" style="text-align: left;"><i class="glyphicon glyphicon-book"></i> ' .Yii::t('common', '{value}_record', ['value'=>$contentName]).'</h3>',
        ],
        'toolbar' => [
        ],
        'pjax'=> false,
        'pjaxSettings'=>[
            'neverTimeout'=>true,
        ]
    ]);

    ActiveForm::end();
    ?>
    <div class="text-left">
        <?php
        echo \yii\widgets\LinkPager::widget([
            'id' => 'user-credit-log_page',
            'pagination'=>$dataProvider->pagination,
        ]);
        ?>
    </div>
</div>
